#ifndef _HARDW_
#define _HARDW_
#include <avr/io.h>

/* 14.7456 MHz */
#define XTAL 14745600L

/* Port B */
#define bo_RS   4
#define bo_LCD  5
#define bo_RW   6
#define bo_KBD  7

/* Port D */
#define di_PF   0
#define di_INT1 1
#define di_INT2 2
#define dom_SEL 0xF0

/* Port E */

/* Port F -- data bus */
#define BUS_OUT DDRF = 0xFF
#define BUS_IN  PORTF = 0xFF; DDRF = 0
#define KBD_ON  DDRF = 0x0F; PORTB &= ~(1<<bo_KBD); asm("nop")
#define KBD_OFF PORTB |= (1<<bo_KBD); PORTF = 0xFF; DDRF = 0

/* Port C */

/* Buttons */
#define SB1         0x0001
#define SB2         0x0002
#define SB3         0x0004
#define SB4         0x0008
#define SB5         0x0010
#define SB6         0x0020
#define SB7         0x0040
#define SB8         0x0080

/* Inputs */
#define IN_SP_UP    0x0100
#define IN_SP_DN1   0x0200
#define IN_PWR	    0x0400
#define IN_CAR_FORW 0x0800
#define IN_CAR_BACK 0x1000
#define IN_SP_READY 0x2000
#define IN_EMRRET	0x4000
#define IN_BRAKE	0x8000

/* Commands */
/*
(S4) (S3) (S2) (S1)
(S8) (S7) (S6) (S5)

S4 - start 
S8 - stop
S3 - carriage forward 
S7 - carriage backward
S2 - table forward
S6 - table backward
S1 - spindle up
S5 - spindle down
*/

#define S_SPUP  SB1
#define S_SPDN  SB5
#define S_TBLF  SB2
#define S_TBLB  SB6
#define S_CARF  SB3
#define S_CARB  SB7
#define S_START SB4
#define S_STOP  SB8

/* Outputs */
//#define OUT_TBLB    0x0001  
#define OUT_COOLANT	0x0001
//#define OUT_TBLF    0x0002
#define OUT_TBLB	0x0002
//#define OUT_SPDN    0x0004
#define OUT_TBLF	0x0004
//#define OUT_SPUP    0x0008
#define OUT_SPDN	0x0008
//#define LED_SPUP    0x0010
#define OUT_SPUP	0x0010
//#define LED_SPDN    0x0020
#define PWR_START	0x0020
//#define LED_CARB    0x0040
#define OUT_BRAKE	0x0040
//#define LED_CARF    0x0080
#define PWR_LATCH	0x0080


// Delay for input change
#define INPUTDELAY 15
// Delay for keyboard debounce
#define KBDELAY 8

#endif
